package org.elanfox.intellicommunity.msg.dto;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.elanfox.intellicommunity.common.utils.HexUtils;
import org.elanfox.intellicommunity.msg.ienum.BaseStationType;
import org.springframework.util.StringUtils;

import java.io.Serializable;

/**
 * @author allan
 * @version 1.0.0
 * @date 2020/3/17
 */
@Data
@NoArgsConstructor
public class CmdWriteParam implements Serializable {
    private static final long serialVersionUID = 6739228118277027691L;
    /**
     * 设备类型
     */
    private BaseStationType stationType;
    /**
     * 阅读器地址
     */
    private long deviceAddr;
    private String hexAddr;

    public String getHexAddr() {
        if (StringUtils.isEmpty(hexAddr)) {
            return stationType.getHexCode() + HexUtils.numToHex8(deviceAddr);
        } else {
            return hexAddr;
        }
    }

    public CmdWriteParam(BaseStationType stationType, long deviceAddr) {
        this.stationType = stationType;
        this.deviceAddr = deviceAddr;
    }
}
